package com.sample.springbatch.job.sample.config;

import com.sample.springbatch.config.BaseConfig;
import com.sample.springbatch.job.sample.reader.ThreadLocalReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class ThreadLocalConfig extends BaseConfig {

    Logger logger = LoggerFactory.getLogger(ThreadLocalConfig.class);

    @Autowired
    ThreadLocalReader threadLocalReader;

    @Bean(name = "threadLocalJob")
    public Job threadLocalJob() {
        return jobBuilderFactory.get("threadLocalJob")
                .incrementer(new RunIdIncrementer())
                .start(threadLocalStep())
                .build();
    }

    @Bean
    public Step threadLocalStep() {
        return stepBuilderFactory.get("threadLocalStep")
                .<String, String> chunk(1)
                .reader(threadLocalReader)
                .processor(threadLocalProcessor())
                .build();
    }

    @Bean
    public ItemProcessor threadLocalProcessor() {
        return new ItemProcessor<String,String>() {

            @Override
            public String process(String item) throws Exception {
                logger.info("time:{}",item);
                return item;
            }
        };
    }
        }
